#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @File  : Paddle第一版本.py
# @Author: Richard Chiming Xu
# @Date  : 2022/7/14
# @Desc  : 基于paddle的第一个版本
#
# import os
# import time
# import json
# import random
# import numpy as np
# import pandas as pd
# from tqdm import tqdm
# from sklearn.metrics import accuracy_score
# from sklearn.model_selection import train_test_split
# import paddle
# import paddlenlp
# import paddle.nn.functional as F
# from functools import partial
# from paddlenlp.data import Stack, Dict, Pad
# from paddlenlp.datasets import load_dataset
# from paddlenlp.transformers.bert.tokenizer import BertTokenizer
# import matplotlib.pyplot as plt
# import seaborn as sns
#
# from transformers import AutoModel
# AutoModel.from_pretrained()
#
#
#
# class Config:
#     # 数据加载部分
#     train_data = {'cn': 'data/中文_train.xlsx', 'en': 'data/英文_train.xlsx', 'ja': 'data/日语_train.xlsx'}
#     max_seq_len = 48  # 句子长度
#     mode = 'train'
#     seed = 2022
#     # 模型部分
#     model_path = 'bert-base-multilingual-cased'  # 本地模型路径
#     model = None  # 模型对象
#     tokenizer = None  # tokenizer对象
#     # 训练部分
#     device = 'cpu'
#     learning_rate = 3e-5
#     train_batch_size = 16  # batch大小
#     val_batch_size = 16
#     test_batch_size = 16
#     ignore_label = -100  # pad slot时设置igore_label的值
#     warmup_proportion = 0.1  # 学习率预热比例
#     weight_decay = 0.01  # 权重衰减系数，类似模型正则项策略，避免模型过拟合
#     max_grad_norm = 1.0
#     epochs = 15  # 训练次数
#     print_loss = 50  # 打印loss次数
#     num_labels = 2  # 分类数
#
#
# # 设置种子
# def set_seed(seed):
#     paddle.seed(seed)
#     random.seed(seed)
#     np.random.seed(seed)
#
#
# # 读取数据
# def read_data(config: Config):
#     if config.mode == 'train':
#         train_cn_df = pd.read_excel(config.train_data['cn'])
#         train_ja_df = pd.read_excel(config.train_data['cn'])
#         train_en_df = pd.read_excel(config.train_data['cn'])
#         return train_cn_df, train_en_df, train_ja_df
#     else:
#         test_ja_df = pd.read_excel('data/testA.xlsx', sheet_name='日语_testA')
#         test_en_df = pd.read_excel('data/testA.xlsx', sheet_name='英文_testA')
#         return pd.concat([test_en_df, test_ja_df], axis=0)
#
#
# # 读取dataloader
# def read_dataloader(config: Config):
#
#
# config = Config()
# set_seed(config.seed)


import tensorflow as tf
from tensorflow.keras import models
from tensorflow.keras.layers import Reshape, Dense, Dropout, Flatten, Conv2D, MaxPool2D, MaxPooling2D
# 定义model
model_nn = tf.keras.Sequential()
model_nn.add(Reshape((28,28,1), input_shape=(784,)))
model_nn.add(Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1)))
model_nn.add(MaxPooling2D((2, 2)))
model_nn.add(Conv2D(64, (3, 3), activation='relu'))
model_nn.add(MaxPooling2D((2, 2)))
model_nn.add(Conv2D(64, (3, 3), activation='relu'))
model_nn.add(Flatten())
model_nn.add(Dense(64, activation='relu'))
model_nn.add(Dense(10, activation='softmax'))
# 打印模型
print(model_nn.to_json())

model = models.model_from_json(model_nn.to_json())
print('--------------------')
print(model.to_json())

